********************************************************************************
** LOAD DATA
********************************************************************************

use "flanders_data.dta", clear

label drop _all

********************************************************************************
** PROBABILITY OF BEING IN GOVERNMENT: EXPECTATIONS
********************************************************************************

* Ordinary least squares regression models
eststo GE1: reg govt_pvda i.party_pvda##c.sophistication_index i.sex age
eststo GE2: reg govt_groen i.party_groen##c.sophistication_index i.sex age
eststo GE3: reg govt_vooruit i.party_vooruit##c.sophistication_index i.sex age
eststo GE4: reg govt_cdv i.party_cdv##c.sophistication_index i.sex age
eststo GE5: reg govt_ovld i.party_ovld##c.sophistication_index i.sex age
eststo GE6: reg govt_nva i.party_nva##c.sophistication_index i.sex age
eststo GE7: reg govt_vb i.party_vb##c.sophistication_index i.sex age

* Regression table
esttab GE1 GE2 GE3 GE4 GE5 GE6 GE7 using "cf_govt_exp_2024.tex", substitute({table} {table*} \begin{tabular*} \footnotesize\begin{tabular*}) wide nonumbers drop(1.party_pvda 1.party_groen 1.party_vooruit 1.party_ovld 1.party_cdv 1.party_nva 1.party_vb 1.sex 1.party_pvda#c.sophistication_index 1.party_groen#c.sophistication_index 1.party_vooruit#c.sophistication_index 1.party_cdv#c.sophistication_index 1.party_ovld#c.sophistication_index 1.party_nva#c.sophistication_index 1.party_vb#c.sophistication_index) refcat(2.party_pvda "\textbf{Party preference}" 2.party_pvda#c.sophistication_index "\textbf{Interaction}" 2.sex "\textbf{Sociodemographics}", nolabel) width(\hsize) b(2) se(2) star(* 0.05) label mtitles("PVDA" "Groen" "Vooruit" "CD\&V" "Open VLD" "N-VA" "VB") style(tex) replace booktabs varlabels(_cons "\textbf{Constant}" 2.party_pvda "\hspace{1em} PVDA" 2.party_groen "\hspace{1em} Groen" 2.party_vooruit "\hspace{1em} Vooruit" 2.party_ovld "\hspace{1em} Open Vld" 2.party_cdv "\hspace{1em} CD\&V" 2.party_nva "\hspace{1em} N-VA" 2.party_vb "\hspace{1em} VB" sophistication_index "\textbf{Political sophistication}" 2.party_pvda#c.sophistication_index "\hspace{1em} PVDA $\times$ Sophistication" 2.party_groen#c.sophistication_index "\hspace{1em} Groen $\times$ Sophistication" 2.party_vooruit#c.sophistication_index "\hspace{1em} Vooruit $\times$ Sophistication" 2.party_cdv#c.sophistication_index "\hspace{1em} CD\&V $\times$ Sophistication" 2.party_ovld#c.sophistication_index "\hspace{1em} Open Vld $\times$ Sophistication" 2.party_nva#c.sophistication_index "\hspace{1em} N-VA $\times$ Sophistication" 2.party_vb#c.sophistication_index "\hspace{1em} VB $\times$ Sophistication" 2.sex "\hspace{1em} Male" age "\hspace{1em} Age") title("OLS Regression Results for Citizens' Expectations, Probability of Being in Government"\label{cf_govt_exp_2024}) order(2.party_pvda 2.party_groen 2.party_vooruit 2.party_cdv 2.party_ovld 2.party_nva 2.party_vb sophistication_index 2.party_pvda#c.sophistication_index 2.party_groen#c.sophistication_index 2.party_vooruit#c.sophistication_index 2.party_cdv#c.sophistication_index 2.party_ovld#c.sophistication_index 2.party_nva#c.sophistication_index 2.party_vb#c.sophistication_index 2.sex age) stats(N r2_a, labels("Observations" "Adjusted-R\textsuperscript{2}") fmt(%9.0fc %9.2fc)) nonotes

eststo clear

********************************************************************************
** PROBABILITY OF BEING IN GOVERNMENT: ACCURACY
********************************************************************************

* Ordinary least squares regression models
eststo GA1: reg govt_pvda_brier i.party_pvda##c.sophistication_index i.sex age
eststo GA2: reg govt_groen_brier i.party_groen##c.sophistication_index i.sex age
eststo GA3: reg govt_vooruit_brier i.party_vooruit##c.sophistication_index i.sex age
eststo GA4: reg govt_cdv_brier i.party_cdv##c.sophistication_index i.sex age
eststo GA5: reg govt_ovld_brier i.party_ovld##c.sophistication_index i.sex age
eststo GA6: reg govt_nva_brier i.party_nva##c.sophistication_index i.sex age
eststo GA7: reg govt_vb_brier i.party_vb##c.sophistication_index i.sex age

* Regression table
esttab GA1 GA2 GA3 GA4 GA5 GA6 GA7 using "cf_govt_acc_2024.tex", substitute({table} {table*} \begin{tabular*} \footnotesize\begin{tabular*}) wide nonumbers drop(1.party_pvda 1.party_groen 1.party_vooruit 1.party_ovld 1.party_cdv 1.party_nva 1.party_vb 1.sex 1.party_pvda#c.sophistication_index 1.party_groen#c.sophistication_index 1.party_vooruit#c.sophistication_index 1.party_cdv#c.sophistication_index 1.party_ovld#c.sophistication_index 1.party_nva#c.sophistication_index 1.party_vb#c.sophistication_index) refcat(2.party_pvda "\textbf{Party preference}" 2.party_pvda#c.sophistication_index "\textbf{Interaction}" 2.sex "\textbf{Sociodemographics}", nolabel) width(\hsize) b(2) se(2) star(* 0.05) label mtitles("PVDA" "Groen" "Vooruit" "CD\&V" "Open VLD" "N-VA" "VB") style(tex) replace booktabs varlabels(_cons "\textbf{Constant}" 2.party_pvda "\hspace{1em} PVDA" 2.party_groen "\hspace{1em} Groen" 2.party_vooruit "\hspace{1em} Vooruit" 2.party_ovld "\hspace{1em} Open Vld" 2.party_cdv "\hspace{1em} CD\&V" 2.party_nva "\hspace{1em} N-VA" 2.party_vb "\hspace{1em} VB" sophistication_index "\textbf{Political sophistication}" 2.party_pvda#c.sophistication_index "\hspace{1em} PVDA $\times$ Sophistication" 2.party_groen#c.sophistication_index "\hspace{1em} Groen $\times$ Sophistication" 2.party_vooruit#c.sophistication_index "\hspace{1em} Vooruit $\times$ Sophistication" 2.party_cdv#c.sophistication_index "\hspace{1em} CD\&V $\times$ Sophistication" 2.party_ovld#c.sophistication_index "\hspace{1em} Open Vld $\times$ Sophistication" 2.party_nva#c.sophistication_index "\hspace{1em} N-VA $\times$ Sophistication" 2.party_vb#c.sophistication_index "\hspace{1em} VB $\times$ Sophistication" 2.sex "\hspace{1em} Male" age "\hspace{1em} Age") title("OLS Regression Results for Citizens' and Politicians' Government Participation Accuracy"\label{cf_govt_acc_2024}) order(2.party_pvda 2.party_groen 2.party_vooruit 2.party_cdv 2.party_ovld 2.party_nva 2.party_vb sophistication_index 2.party_pvda#c.sophistication_index 2.party_groen#c.sophistication_index 2.party_vooruit#c.sophistication_index 2.party_cdv#c.sophistication_index 2.party_ovld#c.sophistication_index 2.party_nva#c.sophistication_index 2.party_vb#c.sophistication_index 2.sex age) stats(N r2_a, labels("Observations" "Adjusted-R\textsuperscript{2}") fmt(%9.0fc %9.2fc)) nonotes

eststo clear

********************************************************************************
** MORE OR LESS SEATS: EXPECTATIONS
********************************************************************************

* Ordinary least squares regression models
eststo SE1: ologit seats_pvda i.party_pvda##c.sophistication_index i.sex age
eststo SE2: ologit seats_groen i.party_groen##c.sophistication_index i.sex age
eststo SE3: ologit seats_vooruit i.party_vooruit##c.sophistication_index i.sex age
eststo SE4: ologit seats_cdv i.party_cdv##c.sophistication_index i.sex age
eststo SE5: ologit seats_ovld i.party_ovld##c.sophistication_index i.sex age
eststo SE6: ologit seats_nva i.party_nva##c.sophistication_index i.sex age
eststo SE7: ologit seats_vb i.party_vb##c.sophistication_index i.sex age

* Regression table
esttab SE1 SE2 SE3 SE4 SE5 SE6 SE7 using "cf_seats_exp_2024.tex", substitute({table} {table*} \begin{tabular*} \footnotesize\begin{tabular*}) wide nonumbers drop(1.party_pvda 1.party_groen 1.party_vooruit 1.party_ovld 1.party_cdv 1.party_nva 1.party_vb 1.sex 1.party_pvda#c.sophistication_index 1.party_groen#c.sophistication_index 1.party_vooruit#c.sophistication_index 1.party_cdv#c.sophistication_index 1.party_ovld#c.sophistication_index 1.party_nva#c.sophistication_index 1.party_vb#c.sophistication_index) refcat(2.party_pvda "\textbf{Party preference}" 2.party_pvda#c.sophistication_index "\textbf{Interaction}" 2.sex "\textbf{Sociodemographics}" cut1 "\textbf{Cut points}", nolabel) width(\hsize) b(2) se(2) star(* 0.05) label mtitles("PVDA" "Groen" "Vooruit" "CD\&V" "Open VLD" "N-VA" "VB") style(tex) replace booktabs varlabels(_cons "\textbf{Constant}" 2.party_pvda "\hspace{1em} PVDA" 2.party_groen "\hspace{1em} Groen" 2.party_vooruit "\hspace{1em} Vooruit" 2.party_ovld "\hspace{1em} Open Vld" 2.party_cdv "\hspace{1em} CD\&V" 2.party_nva "\hspace{1em} N-VA" 2.party_vb "\hspace{1em} VB" sophistication_index "\textbf{Political sophistication}" 2.party_pvda#c.sophistication_index "\hspace{1em} PVDA $\times$ Sophistication" 2.party_groen#c.sophistication_index "\hspace{1em} Groen $\times$ Sophistication" 2.party_vooruit#c.sophistication_index "\hspace{1em} Vooruit $\times$ Sophistication" 2.party_cdv#c.sophistication_index "\hspace{1em} CD\&V $\times$ Sophistication" 2.party_ovld#c.sophistication_index "\hspace{1em} Open Vld $\times$ Sophistication" 2.party_nva#c.sophistication_index "\hspace{1em} N-VA $\times$ Sophistication" 2.party_vb#c.sophistication_index "\hspace{1em} VB $\times$ Sophistication" 2.sex "\hspace{1em} Male" age "\hspace{1em} Age" cut1 "\hspace{1em} Cut point 1" cut2 "\hspace{1em} Cut point 2") title("OLS Regression Results for Citizens' Expectations, Probability of Being in Government"\label{cf_seats_exp_2024}) order(2.party_pvda 2.party_groen 2.party_vooruit 2.party_cdv 2.party_ovld 2.party_nva 2.party_vb sophistication_index 2.party_pvda#c.sophistication_index 2.party_groen#c.sophistication_index 2.party_vooruit#c.sophistication_index 2.party_cdv#c.sophistication_index 2.party_ovld#c.sophistication_index 2.party_nva#c.sophistication_index 2.party_vb#c.sophistication_index 2.sex age cut1 cut2) stats(N r2_p, labels("Observations" "Pseudo-R\textsuperscript{2}") fmt(%9.0fc %9.2fc)) nonotes

eststo clear

********************************************************************************
** MORE OR LESS SEATS: ACCURACY
********************************************************************************

* Logistic regression models
eststo SA1: logit seats_pvda_correct i.party_pvda##c.sophistication_index i.sex age 
eststo SA2: logit seats_groen_correct i.party_groen##c.sophistication_index i.sex age
eststo SA3: logit seats_vooruit_correct i.party_vooruit##c.sophistication_index i.sex age
eststo SA4: logit seats_cdv_correct i.party_cdv##c.sophistication_index i.sex age
eststo SA5: logit seats_ovld_correct i.party_ovld##c.sophistication_index i.sex age
eststo SA6: logit seats_nva_correct i.party_nva##c.sophistication_index i.sex age
eststo SA7: logit seats_vb_correct i.party_vb##c.sophistication_index i.sex age

* Regression table
esttab SA1 SA2 SA3 SA4 SA5 SA6 SA7 using "cf_seats_acc_2024.tex", substitute({table} {table*} \begin{tabular*} \footnotesize\begin{tabular*}) wide nonumbers drop(1.party_pvda 1.party_groen 1.party_vooruit 1.party_ovld 1.party_cdv 1.party_nva 1.party_vb 1.sex 1.party_pvda#c.sophistication_index 1.party_groen#c.sophistication_index 1.party_vooruit#c.sophistication_index 1.party_cdv#c.sophistication_index 1.party_ovld#c.sophistication_index 1.party_nva#c.sophistication_index 1.party_vb#c.sophistication_index) refcat(2.party_pvda "\textbf{Party preference}" 2.party_pvda#c.sophistication_index "\textbf{Interaction}" 2.sex "\textbf{Sociodemographics}", nolabel) width(\hsize) b(2) se(2) star(* 0.05) label mtitles("PVDA" "Groen" "Vooruit" "CD\&V" "Open VLD" "N-VA" "VB") style(tex) replace booktabs varlabels(_cons "\textbf{Constant}" 2.party_pvda "\hspace{1em} PVDA" 2.party_groen "\hspace{1em} Groen" 2.party_vooruit "\hspace{1em} Vooruit" 2.party_ovld "\hspace{1em} Open Vld" 2.party_cdv "\hspace{1em} CD\&V" 2.party_nva "\hspace{1em} N-VA" 2.party_vb "\hspace{1em} VB" sophistication_index "\textbf{Political sophistication}" 2.party_pvda#c.sophistication_index "\hspace{1em} PVDA $\times$ Sophistication" 2.party_groen#c.sophistication_index "\hspace{1em} Groen $\times$ Sophistication" 2.party_vooruit#c.sophistication_index "\hspace{1em} Vooruit $\times$ Sophistication" 2.party_cdv#c.sophistication_index "\hspace{1em} CD\&V $\times$ Sophistication" 2.party_ovld#c.sophistication_index "\hspace{1em} Open Vld $\times$ Sophistication" 2.party_nva#c.sophistication_index "\hspace{1em} N-VA $\times$ Sophistication" 2.party_vb#c.sophistication_index "\hspace{1em} VB $\times$ Sophistication" 2.sex "\hspace{1em} Male" age "\hspace{1em} Age") title("OLS Regression Results for Citizens' and Politicians' Government Participation Accuracy"\label{cf_seats_acc_2024}) order(2.party_pvda 2.party_groen 2.party_vooruit 2.party_cdv 2.party_ovld 2.party_nva 2.party_vb sophistication_index 2.party_pvda#c.sophistication_index 2.party_groen#c.sophistication_index 2.party_vooruit#c.sophistication_index 2.party_cdv#c.sophistication_index 2.party_ovld#c.sophistication_index 2.party_nva#c.sophistication_index 2.party_vb#c.sophistication_index 2.sex age) stats(N r2_p, labels("Observations" "Pseudo-R\textsuperscript{2}") fmt(%9.0fc %9.2fc)) nonotes

eststo clear

********************************************************************************
** MORE OR LESS SEATS: EXPECTATIONS -- SECOND DIFFERENCES
********************************************************************************

local parties pvda groen vooruit cdv ovld nva vb

foreach p of local parties {
    disp "Running for party: `p'"

    ologit seats_`p' i.party_`p'##c.sophistication_index i.sex age

    margins, at(sophistication_index=gen(sophistication_index)) ///
        at(sophistication_index=gen(sophistication_index + 1)) ///
        over(party_`p') post

    mlincom, clear

    * Fewer seats
    qui mlincom 3 - 1, stat(est se p) add rowname("AME: L_Non`p'")
    qui mlincom 4 - 2, stat(est se p) add rowname("AME: L_`p'")

    * Same as now
    qui mlincom 7 - 5, stat(est se p) add rowname("AME: S_Non`p'")
    qui mlincom 8 - 6, stat(est se p) add rowname("AME: S_`p'")

    * More seats
    qui mlincom 11 - 9, stat(est se p) add rowname("AME: M_Non`p'")
    qui mlincom 12 - 10, stat(est se p) add rowname("AME: M_`p'")

    * Second Difference: Fewer seats
    qui mlincom (4 - 2) - (3 - 1), stat(est se p) add rowname("2nd Diff: L_`p'_Non`p'")

    * Second Difference: Same as now
    qui mlincom (8 - 6) - (7 - 5), stat(est se p) add rowname("2nd Diff: S_`p'_Non`p'")

    * Second Difference: More seats
    qui mlincom (12 - 10) - (11 - 9), stat(est se p) add rowname("2nd Diff: M_`p'_Non`p'")

    mlincom, stat(est se p) title("AMEs and Test of 2nd Difference for `p'")
}

********************************************************************************
** MORE OR LESS SEATS: ACCURACY -- SECOND DIFFERENCES
********************************************************************************

local parties pvda groen vooruit cdv ovld nva vb

foreach p of local parties {
    disp "Running logit and margins for party: `p'"

    logit seats_`p'_correct i.party_`p'##c.sophistication_index i.sex age

    margins, at(sophistication_index=gen(sophistication_index)) ///
        at(sophistication_index=gen(sophistication_index + 1)) ///
        over(party_`p') post

    mlincom, clear

    * Effect of +1 on sophistication index for respondents who felt close to another party
    qui mlincom 3 - 1, stat(est se p) add rowname("AME: Non`p'")

    * Effect of +1 on sophistication index for respondents who felt close to `p`
    qui mlincom 4 - 2, stat(est se p) add rowname("AME: `p'")

    * Second Difference
    mlincom (4 - 2) - (3 - 1), stat(est se p) add rowname("2nd Diff for `p'")
}